//
//  WorkOrderStore.m
//  NewPro
//
//  Created by RYX on 2018/11/24.
//  Copyright © 2018年 何荧红. All rights reserved.
//

#import "WorkOrderStore.h"
#import "WorkOrderModel.h"
#import "WorkOrderDetailModel.h"
#import "PostWorkOrderDataParameters.h"

@implementation WorkOrderStore

#pragma mark - 获取工单处理列表
- (void)getWorkOrderListWithCustomId:(NSString *)customId Success:(void(^)(NSArray *listArr))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/workOrder/workOrderList",IP];
    NSDictionary *dic = @{
                          @"customId":customId
                          };
    [HttpTool postUrlWithString:url parameters:dic success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        
        if (error == nil) {
            
            NSArray *arr = [WorkOrderModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"items"]];
            success(arr);
        }else{
            
            failure(error);
        }
        
    } failure:^(NSError *error) {
        
        failure(error);
    }];
    
}

#pragma mark - 获取已处理工单列表
- (void)getWorkOrderProcessedListWithCustomId:(NSString *)customId Success:(void(^)(NSArray *listArr))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/workOrder/workOrderProcessed",IP];
    NSDictionary *dic = @{
                          @"customId":customId
                          };
    [HttpTool postUrlWithString:url parameters:dic success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        
        if (error == nil) {
            
            NSArray *arr = [WorkOrderModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"items"]];
            success(arr);
        }else{
            
            failure(error);
        }
        
    } failure:^(NSError *error) {
        
        failure(error);
    }];
    
}

#pragma mark - 获取工单详情
- (void)getWorkOrderDetailWithWorkOrderId:(NSString *)workOrderId Success:(void(^)(WorkOrderDetailModel *model))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/workOrder/workOrderDetails",IP];
    NSDictionary *dic = @{
                          @"workOrderId":workOrderId
                          };
    [HttpTool postUrlWithString:url parameters:dic success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        
        if (error == nil) {
            
            WorkOrderDetailModel *model = [WorkOrderDetailModel mj_objectWithKeyValues:responseObject[@"data"][@"items"]];
            
            success(model);
            
        }else{
            
            failure(error);
        }
        
    } failure:^(NSError *error) {
        
        failure(error);
    }];
    
}


#pragma mark - 工单审核资料提交
- (void)postWorkOrderDataWithWorkWithParameters:(PostWorkOrderDataParameters *)parameters Success:(void(^)(void))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/workOrder/workOrderSubmit",IP];
    NSDictionary *dic = @{
                          @"customId":parameters.customId,
                          @"workOrderId":parameters.workOrderId,
                          @"idCardFront":parameters.idCardFront,
                          @"idCardBack":parameters.idCardBack,
                          @"holdIdCardFront":parameters.holdIdCardFront,
                          @"bankFront":parameters.bankFront,
                          @"bankBack":parameters.bankBack,
                          @"holdBankFront":parameters.holdBankFront,
                          @"payment":parameters.payment,
                          @"holdPayment":parameters.holdPayment,
                          
                          };
    
    NSMutableDictionary *pars = [NSMutableDictionary dictionaryWithDictionary:dic];
    
    if (parameters.payableBills.length > 0) {
        
        [pars setObject:parameters.payableBills forKey:@"payableBills"];
    }
    
    [HttpTool postUrlWithString:url parameters:pars success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        
        if (error == nil) {
            
            success();
        }else{
            
            failure(error);
        }
        
    } failure:^(NSError *error) {
        
        failure(error);
    }];
    
}

#pragma mark - 获取消费证明模板
- (void)getConsumptionURLSuccess:(void(^)(NSString *imgStr))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/workOrder/getConsumptionURL",IP];
    
    [HttpTool postUrlWithString:url parameters:nil success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        
        if (error == nil) {
            
            NSString *imgStr = responseObject[@"data"][@"items"];
            
            success(imgStr);
            
        }else{
            
            failure(error);
        }
        
    } failure:^(NSError *error) {
        
        failure(error);
    }];
    
}

@end
